package LeetCode.linkedlist;

public class TestReverse {
    public static  ListNode crate(){
        ListNode head = new ListNode(0);
        ListNode node = head;
        for(int i=1;i<4;i++){
            node.next = new ListNode(i);
            node = node.next;
        }
        return head;
    }

    public static void show(ListNode head){
        ListNode node = head;
        while(node != null){
            System.out.println(node.var);
            node = node.next;
        }
    }

    public static ListNode reverse(ListNode head){
        ListNode curr = head;
        ListNode pre = null;
        ListNode temp;
        while(curr != null){
            temp = curr.next;
            curr.next = pre;
            pre = curr;
            curr = temp;
        }

        return pre;
    }

    public static void main(String[] args) {
        ListNode head = TestReverse.crate();
        TestReverse.show(head);
        ListNode node = TestReverse.reverse(head);
        TestReverse.show(node);
    }
}
